﻿using SVTTranslateTextEngine.Properties;

namespace SVTTranslateTextEngine.TTChecker
{
    /// <summary>
    /// Achieve validation logic of text context in the translation process .
    /// </summary>
    public class TextChecker
    {
        protected const string ERR_TEXT_LEN_TOO_LARGE = "The text length is too large ! \r\n",
                               ERR_TEXT_NOT_ALLOW_TO_FILE =
                                   "The text length is too large, and can't return the translation by file transmission model ! \r\n";

        /// <summary>
        /// Check the text is allowed to running the translation process ,or not ?
        /// </summary>
        /// <param name="szTextContext">the context which will be in the text input parameter .</param>
        /// <returns>error message , empty is right </returns>
        public string CheckTextIsCanTranslate(string szTextContext)
        {
            string errorMessage = "";
            if (!CheckTheTextLengthIsAllowed(szTextContext))
                errorMessage = ERR_TEXT_LEN_TOO_LARGE;
            if (!CheckIsTranslateTextToFile())
                errorMessage = ERR_TEXT_NOT_ALLOW_TO_FILE;
            return errorMessage;
        }

        /// <summary>
        /// Check the setting is can translate by text to file model , or not ?
        /// </summary>
        /// <returns>true or false </returns>
        public bool CheckIsTranslateTextToFile()
        {
            return Settings.Default.TranslateTextToFile == "Y";
        }

        /// <summary>
        /// Check the context' length is allowed to running the translation process , or not ?
        /// </summary>
        /// <param name="szTextContext">context which will be in the text input parameter </param>
        /// <returns>true or false </returns>
        public bool CheckTheTextLengthIsAllowed(string szTextContext)
        {
            return szTextContext.Length <= Settings.Default.TextToTextMaxLength;
        }
    }
}